<template>
  <div class="upload-image">
    <!-- 上传按钮 -->
    <div class="upload-image-btn">
      <label :for="for_Id">
        <div class="iconfont icon-add">&#xe60d;</div>
      </label>
      <input
        type="file"
        accept="audio/*"
        :id="for_Id"
        multiple
        style="display: none"
        @change="uploadAudio($event)"
      />
    </div>
    <div class="upload-row">
      <div class="upload-desc">
        <div class="desc-row">{{ item.title }}</div>
        <div class="desc-row">{{ item.reqtext }}</div>
      </div>
      <div v-if="item.files" class="file-list">
        <div v-for="(file, k) in item.files" :key="k" class="file-list-item">
          <div class="iconfont icon-audio">&#xe6ed;</div>
          <div class="iconfont icon-del" @click="deleteAudio(k)">&#xe650;</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    for_Id: {
      default: "img",
    },
    item: {
      default: () => {},
    },
  },
  methods: {
    uploadAudio(e) {
      let f = e.target.files;
      let files = {};
      for (let k in f) {
        if (k == "length" || k == "item") {
          continue;
        }
        files[k] = f[k];
      }
      e.target.value = "";
      this.$emit("uploadAudio", files);
    },
    deleteAudio(k) {
      this.$emit("deleteAudio", k);
    },
  },
};
</script>

<style lang="less" scoped>
.upload-image {
  display: flex;
  width: 100%;
  margin-bottom: 30px;
  .upload-row {
    width: 100%;
    .upload-desc {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      width: 100%;
      height: 80px;
      padding: 10px 0;
      box-sizing: border-box;
      margin-bottom: 15px;
      .desc-row {
        color: #88898E;
      }
    }
    .file-list {
      flex-grow: 1;
      display: flex;
      .file-list-item {
        position: relative;
        width: 80px;
        height: 80px;
        margin-right: 15px;
        &:hover .icon-del {
          display: block;
        }
        .icon-audio {
          width: 100%;
          height: 100%;
          line-height: 80px;
          border-radius: 5px;
          font-size: 28px;
          color: #387CF7;
          text-align: center;
          background-color: #fff;
          user-select: none;
          cursor: pointer;
        }
        .icon-del {
          display: none;
          position: absolute;
          left: 0;
          top: 0;
          width: 100%;
          height: 100%;
          line-height: 80px;
          border-radius: 5px;
          font-size: 28px;
          color: #387CF7;
          text-align: center;
          background-color: rgba(0, 0, 0, 0.4);
          user-select: none;
          cursor: pointer;
        }
      }
    }
  }
  .upload-image-btn {
    flex-shrink: 0;
    width: 100px;
    height: 80px;
    margin-right: 10px;
    label {
      position: relative;
      display: flex;
      align-items: center;
      justify-content: center;
      width: 100%;
      height: 100%;
      border-radius: 10px;
      user-select: none;
      cursor: pointer;
      padding: 5px;
      box-sizing: border-box;
      background-color: #f4f7fc;
      .icon-add {
        color: #387CF7;
        font-size: 32px;
      }
    }
  }
}
</style>